package com.drinks.yiniang.ui.widget.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.drinks.yiniang.R;
import com.hansen.library.utils.AppUtils;
import com.hansen.library.utils.ScreenSizeUtils;

/**
 * @author han
 * @date 2019/8/30
 */
public class HomeHeaderBackgroundView extends View {
    private int barHeight = 0;

    public HomeHeaderBackgroundView(Context context) {
        this(context, null);
    }

    public HomeHeaderBackgroundView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public HomeHeaderBackgroundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        barHeight = context.getResources().getDimensionPixelSize(R.dimen.height_home_header_bkg);

        //加上&& !isInEditMode() 判断是因为在EditMode模式下，会出现exception
        if ((AppUtils.isVersionCodeGreaterThanOrEqualToKITKAT()) && !isInEditMode()) {
            barHeight += (int) ScreenSizeUtils.getStatusBarHeightWithAndroid(context);
        }

        int navBarHeight = context.getResources().getDimensionPixelSize(R.dimen.height_navigation_bar);

        barHeight += navBarHeight;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int widthSize = MeasureSpec.getSize(widthMeasureSpec);

        setMeasuredDimension(widthSize, barHeight);
    }
}
